//
//  WBBaseNavigationController.m
//  TransWB
//
//  Created by 孝飞王 on 2016/12/27.
//  Copyright © 2016年 孝飞王. All rights reserved.
//

#import "WBBaseNavigationController.h"
#import "WBBaseViewController.h"
@interface WBBaseNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation WBBaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.interactivePopGestureRecognizer.delegate = self;
    self.navigationBar.hidden = YES;
}

- (void)pushViewController:(UIViewController *)viewControlle animated:(BOOL)animated{
    
    WBBaseViewController *viewController =(WBBaseViewController*)viewControlle;
    if (self.viewControllers.count>0){
        
           NSString *string = @"返回";
        
        if (self.childViewControllers.count == 1){
            string = self.viewControllers.firstObject.title;
        }
        
//        UIBarButtonItem *newsBtnItem = [[UIBarButtonItem alloc]initWithTitle:string style:UIBarButtonItemStylePlain target:self action:@selector(leftBtnClick)];
        viewController.navItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:[UIButton cz_titleAndImage:@"navigationbar_back_withtext" title:string taget:self action:@selector(leftBtnClick)]];
        
//        //解决不能靠左的问题
//        UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
//        
//        nagetiveSpacer.width = -10;//这个值可以根据自己需要自己调整
        
       // self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, newsBtnItem];
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    
    [super pushViewController:viewController animated:animated];
}

//返回按钮
- (void)leftBtnClick{
    
    [self popViewControllerAnimated:YES];
}


#pragma mark - 修复返回手势  
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    
    return self.childViewControllers.count > 1;
}


@end
